<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>猜数字</title>
</head>
<body>
<input type="text" id="i1" placeholder="请输入0-100的整数">
<input type="button" value="猜一猜" onclick="fn()">
<div id="d1"></div>

<script>
//生成一个0-100的随机整数
    let x = parseInt(Math.random()*101);
    let count=0;
    function  fn() {
        count++;
        //判断用户输入的值和x的关系
        if(i1.value>x){
            d1.innerText = "猜大了!"
        }else if(i1.value<x){
            d1.innerText = "猜小了"
        }else{
            d1.innerText = "恭喜你第"+count+"次猜对了!"
        }


    }





</script>

</body>
</html>